/*
 * @Author: ZhangJJ zhangjinjia666@outlook.com
 * @Date: 2024-05-05 11:09:37
 * @LastEditors: ZhangJJ zhangjinjia666@outlook.com
 * @LastEditTime: 2024-05-05 11:10:58
 * @FilePath: \vue_login_book\nestjs-book-admin\src\modules\auth\auth.controller.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Body, Controller, Post, UseFilters } from '@nestjs/common';
import { HttpExceptionFilter } from 'src/exception/http-exception.filter';
import { wrapperResponse } from 'src/utils';
import { AuthService } from './auth.service';
import { Public } from './public.decorator';

@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  @Public() // 将login接口的public属性标识为true，表示公共接口，没有token也可以访问，不再经过路由守卫
  @Post('login')
  @UseFilters(new HttpExceptionFilter()) // 绑定异常过滤器，用于处理异常返回的格式
  login(@Body() params) {
    return wrapperResponse(
      this.authService.login(params.username, params.password),
      '登录成功',
    );
  }
}
